<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/4/24
 * Time: 15:46
 */

namespace App\Rep;


use App\Models\ManagementCard;

class ManagementCardRep
{

    /**
     * 获取抽号机管理卡列表
     * @param $params
     */
    public function getManagementCardListRep($params){
        return ManagementCard::Search($params)->orderBy('id','desc')->paginate($params['per_page']??10);
    }

    /**
     * 添加管理卡
     * @param $params
     */
    public function createManagementCardRep($params){
        if(isset($params['id']) && !empty($params['id'])){
            $model = ManagementCard::where('id',$params['id'])->first();
            $model->card_name = $params['card_name'];
            $model->card_number = $params['card_number'];
            $model->remark = $params['remark'];
            $model->save();
        }else{
            ManagementCard::updateOrCreate(
                ['card_number'=>$params['card_number']],
                [
                    'card_name'=>$params['card_name'],
                    'card_number' => $params['card_number'],
                    'remark' => $params['remark'],
                ]
            );
        }
        return ['code'=>0,'msg'=>'success','data'=>[]];
    }


    //删除
    public function delManagementCardRep($params){
        $model = ManagementCard::find($params['id']);
        $model->is_del = $params['is_del'];
        $model->save();
        return ['code'=>0,'msg'=>'success','data'=>[]];
    }



}